﻿@using Telerik.Web.Mvc.UI;
@{
    //page title
    ViewBag.Title = T("Admin.Configuration.Measures.Dimensions").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
        @T("Admin.Configuration.Measures.Dimensions")
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            <strong>@T("Admin.Configuration.Measures.Dimensions.Description")</strong>
        </td>
    </tr>
    <tr>
        <td>
            @(Html.Telerik().Grid<MeasureDimensionModel>()
                    .Name("measuredimension-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Name).Width(200);
                        columns.Bound(x => x.SystemKeyword).Width(150);
                        columns.Bound(x => x.Ratio).Width(100).Format("{0:G29}");
                        columns.Bound(x => x.DisplayOrder).Width(100);
                        columns.Bound(x => x.IsPrimaryDimension)
                            .Template(
                                @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.IsPrimaryDimension.ToString().ToLowerInvariant() + ".gif")" />
                            )
                            .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= IsPrimaryDimension #>.gif' />")
                            .Centered()
                            .Width(100)
                            .ReadOnly();
                        columns.Bound(x => x.Id)
                            .Template(x => Html.ActionLink(T("Admin.Configuration.Measures.Dimensions.Fields.MarkAsPrimaryDimension").Text, "MarkAsPrimaryDimension", new { id = x.Id }, new { @class = "t-button" }))
                            .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Measure/MarkAsPrimaryDimension/") + "<#= Id #>\" class=\"t-button\">" + T("Admin.Configuration.Measures.Dimensions.Fields.MarkAsPrimaryDimension").Text + "</a>")
                            .Centered()
                            .HeaderTemplate(T("Admin.Configuration.Measures.Dimensions.Fields.MarkAsPrimaryDimension").Text)
                            .Width(100)
                            .ReadOnly();
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                        }).Width(180);

                    })
                    .ToolBar(x => x.Insert())
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("Dimensions", "Measure")
                            .Update("DimensionUpdate", "Measure")
                            .Delete("DimensionDelete", "Measure")
                            .Insert("DimensionAdd", "Measure");
                    })
                    .ClientEvents(x => x.OnError("grid_onError"))
                    .EnableCustomBinding(true))
            <script type="text/javascript">
                function grid_onError(e) {
                    alert(e.XMLHttpRequest.responseText);
                    e.preventDefault();
                }
            </script>
        </td>
    </tr>
</table>
